﻿using ZR.Admin.WebApi.Filters;
using ZR.Model.Souvenir;
using ZR.Model.Souvenir.Dto;
using ZR.Service.Souvenir.IService;

namespace ZR.Admin.WebApi.Controllers.Souvenir
{
/// <summary>
    /// 收货地址
    /// </summary>
    [Verify]
    [Route("business/ShippingAddress")]
    public class ShippingAddressController : BaseController
    {
        /// <summary>
        /// 收货地址接口
        /// </summary>
        private readonly IShippingAddressService _shippingAddressService;

        public ShippingAddressController(IShippingAddressService shippingAddressService)
        {
            _shippingAddressService = shippingAddressService;
        }

        /// <summary>
        /// 查询收货地址列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public IActionResult QueryShippingAddress([FromQuery] ShippingAddressQueryDto parm)
        {
            var response = _shippingAddressService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询收货地址详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        public IActionResult GetShippingAddress(int Id)
        {
            var response = _shippingAddressService.GetInfo(Id);
            
            var info = response.Adapt<ShippingAddress>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加收货地址
        /// </summary>
        /// <returns></returns>
        [HttpPost("")]
        public IActionResult AddShippingAddress([FromBody] ShippingAddressDto parm)
        {
            var modal = parm.ToCreate(HttpContext);

            var response = _shippingAddressService.AddShippingAddress(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新收货地址
        /// </summary>
        /// <returns></returns>
        [HttpPut("")]
        public IActionResult UpdateShippingAddress([FromBody] ShippingAddressDto parm)
        {
            var modal = parm.ToUpdate(HttpContext);
            var response = _shippingAddressService.UpdateShippingAddress(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除收货地址
        /// </summary>
        /// <returns></returns>
        [HttpDelete("{ids}")]
        public IActionResult DeleteShippingAddress(string ids)
        {
            int[] idsArr = Tools.SpitIntArrary(ids);
            if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }

            var response = _shippingAddressService.Delete(idsArr);

            return ToResponse(response);
        }


    }
}